package com.example.teaching_server.controller;

import com.example.teaching_server.common.ApiResponse;
import com.example.teaching_server.entity.ActivityCategory;
import com.example.teaching_server.service.ActivityService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/activities")
@RequiredArgsConstructor
@Tag(name = "活动管理", description = "活动相关接口")
public class ActivityController {

    private final ActivityService activityService;

    /**
     * 获取所有活动分类
     */
    @GetMapping("/categories")
    @Operation(summary = "获取活动分类列表", description = "获取所有活动分类的详细信息")
    public ApiResponse<List<ActivityCategory>> getActivityCategories() {
        log.info("开始获取活动分类列表");

        try {
            List<ActivityCategory> categories = activityService.getAllActivityCategories();
            log.info("成功获取{}个活动分类", categories.size());
            return ApiResponse.success("活动分类获取成功", categories);
        } catch (Exception e) {
            log.error("获取活动分类失败", e);
            return ApiResponse.fail("获取活动分类失败: " + e.getMessage());
        }
    }
}
